// // const WebSocket = require('ws'); // vite项目是通过 ES model 模式，所以不能使用 require
// import WebSocket from 'ws';
// // webscoket.clinet :客户端 webscoket.sever : 服务端
// let webSocketServer = new WebSocket.Server({port:'8080'});


// var express = require('express');
// var http = require('http');
// var WebSocket = require('ws');
import WebSocket from 'ws';
// let app = express();
// let server = http.createServer(app);
let webSocketServer = new WebSocket.Server({port:'8080'});


//服务和链接 长链接
// 可能有多个用户连接
let pool = new Map(); // 存储我们的连接用户
let num = 0;
webSocketServer.on('connection',(ws)=>{
    num += 1;
    pool.set('connection' + num,ws)

    // nodejs的事件体系
    ws.on('message',(mes)=>{
        console.log(mes)
    })
    ws.on('close',()=>{

    })
    ws.on('error',()=>{
        console.log('错误')
    })
})
